package com.sskj.b70.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.R;
import com.sskj.b70.common.App;
import com.sskj.b70.common.Constants;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.bean.UserInfo;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.SPUtils;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.fragment.MineFragment;


/**
 * Created by Lee on 2018/1/25 0025.
 */

public class MinePresenter extends BasePresenter<MineFragment> {

    public void requestUserInfo() {
        httpService.getUserInfo()
                .execute(new JsonCallBack<HttpData<UserInfo>>(this, false) {
                    @Override
                    public void _onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.STATUS_OK) {
                            if (httpData.getData() != null) {
                                if (httpData.getData().getDisable()==1){
                                    MyAppLication.getApplication().logout();
                                }
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_IS_SHOP, httpData.getData().isIs_shop());
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME, httpData.getData().getRealname());
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_ACCOUNTPER, httpData.getData().getAccount());
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_TEL, httpData.getData().getMobile());
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_MOBILE, httpData.getData().getMobile());
                                mView.updateUserTitle(httpData.getData());
                            }
                        }
                    }
                });
    }

    public void sign() {
        OkGo.<HttpData<CoinGetBean>>post(HttpConfig.BASE_URL + HttpConfig.SIGN)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData<CoinGetBean>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<CoinGetBean>> response) {
                        HttpData<CoinGetBean> httpListData = response.body();
                        if (httpListData.getStatus() == HttpConfig.STATUS_OK) {
                            ToastUtil.showLong(App.INSTANCE.getString(R.string.strMinePresenter1) + httpListData.getData().bz + App.INSTANCE.getString(R.string.strMinePresenter2) + httpListData.getData().num + App.INSTANCE.getString(R.string.strMinePresenter3));
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }

                });
    }

    class CoinGetBean {
        String bz;
        String num;
    }

}
